from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get('https://www.baidu.com')

print(driver.title)
kw = driver.find_element(By.ID, 'kw')
print(kw.get_attribute('outerHTML'))

# EC.title_is(str)
result1 = WebDriverWait(driver, 10).until(EC.title_is('百度一下，你就知道'), message='标题')
print(result1)

# EC.presence_of_element_located(locator)  locator是一个为(By,value)的元组,添加括号
result2 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'kw')), message='搜索框')
print(result2)

# *拆包
t1 = (By.ID, 'kw')
t2 = [By.ID, 'kw']
kw1 = driver.find_element(*t1)
kw2 = driver.find_element(*t2)

print(kw1.get_attribute('outerHTML'))
print(kw2.get_attribute('outerHTML'))

driver.quit()
